package com.meepo.framework.design.grid;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

class WidgetAdapter extends RecyclerView.Adapter<GridViewHolder> {

    private final List<GridItem> items;
    private final Context mContext;

    public WidgetAdapter(Context context, List<GridItem> items) {
        this.items = items;
        this.mContext = context;
    }

    @NonNull
    @Override
    public GridViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RelativeLayout rootView = new RelativeLayout(mContext);
        return new GridViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(@NonNull GridViewHolder holder, int position) {
        holder.addChildView(items.get(position));
    }

    @Override
    public int getItemCount() {
        return items.size();
    }
}
